﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows.Forms;

namespace DAQ.Common
{
   public class Wait
    {
        public static bool WithCondition(Func<bool> func,int timeout)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            while(sw.ElapsedMilliseconds<timeout)
            {
                if (func())
                    return true;
                Application.DoEvents();
                Delay(10);
            }
            return false;
        }
        public static void Delay(int timeout)
        {
            System.Threading.Thread.Sleep(timeout);
        }
    }
}
